using System;
using System.IO;
using System.Text;

namespace b64
{
	class Program
	{
		static void Main(string[] args)
		{
			if (args.Length == 3 && args[0][0] == '-')
			{
				try
				{
					switch (args[0][1])
					{
						case 'e':
							File.WriteAllText(args[2], Convert.ToBase64String(File.ReadAllBytes(args[1])));
							break;
						case 'd':
							File.WriteAllBytes(args[2], Convert.FromBase64String(File.ReadAllText(args[1])));
							break;
					}
				}
				catch (Exception ex)
				{
					Console.WriteLine(ex.Message);
				}
			}
			else
			{
				Console.Write("b64 usage: b64 <option> <input> <output>\n" +
					"\toptions:\n" +
					"\t\t-e stand for encode\n" +
					"\t\t-d stand for decode.");
			}
		}
	}
}
